package com.dynamicAgent;

import java.lang.reflect.Proxy;

/**
 * Project: tobe-better-coder
 * Package: com.dynamicAgent
 *
 * @author : Mr.xu
 * @date : 2023/3/25 4:57
 */
public class Test {
    public static void main(String[] args) {
//        Animal animal = new Cat();
//        InvocationHandlerDemo<Animal> animalInvocationHandlerDemo = new InvocationHandlerDemo<>(animal);
//        Animal animalProxy = (Animal) Proxy.newProxyInstance(Animal.class.getClassLoader(),new Class<?>[]{Animal.class},animalInvocationHandlerDemo);
//        Animal animalProxy = (Animal) Proxy.newProxyInstance(Test.class.getClassLoader(), new Class<?>[]{Animal.class}, new InvocationHandler() {
//            Animal animal = new Dog();
//            @Override
//            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//
//                return method.invoke(animal,args);
//            }
//        });
//        animalProxy.getAgeByName("Tom");

        Grass tree = new Grass();
        tree.method();
        InvocationHandlerDemo<Plant> plantInvocationHandlerDemo = new InvocationHandlerDemo<>(tree);
        Plant plantProxy = (Plant) Proxy.newProxyInstance(Plant.class.getClassLoader(), new Class<?>[]{Plant.class}, plantInvocationHandlerDemo);
        plantProxy.method();
    }
}